#include "ArrayOpt.h"
#include <limits.h>
#include <iostream>



ArrayOpt::ArrayOpt()
{
}


ArrayOpt::~ArrayOpt()
{
}

void ArrayOpt::BubbleSort(int arr[], int len)
{
	int index = 0;
	int temp = INT_MIN;
	/*for (int i = len; i >= 1; i--)
	{
		for (int j = 0; j < len - 1; j++)
		{
			if (arr[j] > arr[j + 1])
			{
				temp = arr[j];
				arr[j] = arr[j + 1];
				arr[j + 1] = temp;
			}
			index++;
		}
	}*/

	for (int i = 0; i < len	- 1; i ++)
	{
		for (int j = 0; j < len - 1 - i; j++)
		{
			if (arr[j] > arr[j+1])
			{
				temp = arr[j];
				arr[j] = arr[j + 1];
				arr[j + 1] = temp;
			}
			index++;
			
		}
	}
	std::cout << index << "\n";
}

void ArrayOpt::SelectionSort(int arr[], int len)
{
	int index = 0;

	int minIndex = 0;
	int temp = 0;
	for (int i = 0; i < len - 1; i++)
	{
		minIndex = i;
		for (int j = i + 1; j < len; j++)
		{
			if (arr[j] < arr[minIndex])
			{
				minIndex = j;
			}
			index++;
		}
		temp = arr[i];
		arr[i] = arr[minIndex];
		arr[minIndex] = temp; 
	}

	std::cout << index << "\n";
}
